﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using Commonlib;

namespace AlbonWeb.Order.ashx
{
    /// <summary>
    /// Summary description for Handler1
    /// </summary>
    public class Handler1 : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (context.Request["modelid"] != null)
            {
                context.Response.Write(getKeyValue(context));
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
        private string getKeyValue(HttpContext context) 
        {
            string keyvalue = "";
            string cmdstr = "select * from ModelStyle where modelID="+context.Request["modelid"].ToString();
            DataTable dt = SqlHelper.ExecuteDataSet(SqlHelper.SqlConnectionString, CommandType.Text, cmdstr, null).Tables[0];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                //根据ID重新从Style表中读取数据，如果样式信息被改动过，则显示更改后的styleName
                string valueid = dt.Rows[i]["valueID"].ToString();
                string value = "";
                cmdstr = "select styleName from Style where ID in (" + valueid + ")";
                DataTable dtstyle = SqlHelper.ExecuteDataSet(SqlHelper.SqlConnectionString, CommandType.Text, cmdstr, null).Tables[0];
                if (dtstyle.Rows.Count != 0)
                {
                    for (int j = 0; j < dtstyle.Rows.Count; j++)
                    {
                        value += dtstyle.Rows[j]["styleName"].ToString() + ",";
                    }
                    value = value.Substring(0, value.Length - 1);
                }

                keyvalue += dt.Rows[i]["keyID"].ToString() + "=" + valueid + "=" + value + "$";
            }
            if (keyvalue.Length != 0)
            {
                keyvalue = keyvalue.Substring(0, keyvalue.Length - 1);
            }
            return keyvalue;
        }
    }
}